﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.IO;
using System.Text;

namespace GPCSC.Web.SHFW
{
    /// <summary>
    /// GCGS1 的摘要说明
    /// </summary>
    public class GCGS1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

             StringBuilder adds = new StringBuilder();
            string strXMLPath = context.Server.MapPath("~/SHFW/GCGS.xml");
            XmlDocument xml = new XmlDocument();
            xml.Load(strXMLPath);
            XmlNode root = xml.SelectSingleNode("/root");
            XmlNodeList childlist = root.ChildNodes;

            string type = context.Request["type"].ToString();
            
            if (type == "lb")
            {
                //页面初始化 首次加载类别
                adds.Clear();
               
                if (childlist.Count > 0)
                {
                    foreach (XmlNode XN in childlist)
                    {
                        adds.Append("<option value='" + XN.Attributes["value"].Value.ToString() + "'>" + XN.Attributes["name"].Value.ToString() + "</option>");
                    }
                }
               
            }
            else if (type == "nr")
            {
                //类别改变  加载内容
                adds.Clear();
                string lbv = context.Request["lbv"].ToString();
                if (childlist.Count > 0)
                {
                    foreach (XmlNode XN in childlist)
                    {
                        if (XN.Attributes["value"].Value.ToString() == lbv)
                        {
                            XmlNodeList cdlist = XN.ChildNodes;
                            foreach (XmlNode xns in cdlist)
                            {
                                adds.Append("<option value='" + xns.Attributes["value"].Value.ToString() + "'>" + xns.InnerText + "</option>");
                            }
                        }
                        
                    }
                }

            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(adds.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}